# from PIL import Image
# from torch.utils.tensorboard import SummaryWriter
# from torchvision import transforms
#
# writer=SummaryWriter("logs")
# img=Image.open("D:\\PytorchLearn\\pytorch_learning\\Project1\\images\\capture_20221115110104367.bmp")
#
# trans_totensor=transforms.ToTensor()
# img_tensor=trans_totensor(img)
# writer.add_image("ToTensor",img_tensor)
#
# print(img_tensor[0][0][0])
# trans_norm=transforms.Normalize([5,5,5,],[5,5,5])
# img_norm=trans_norm(img_tensor)
# writer.add_image("Normalize",img_norm,2)
#
# trans_resize=transforms.Resize((512,512))
# # img PIL -> resize->PIL
# img_resize=trans_resize(img)
# # img_resize PIL->totensor-> tensor
# img_resize=trans_totensor(img_resize)
# writer.add_image("Resize",img_resize,3)
#
# print(img_resize)
#
# # Compose - resize -2
# trans_resize_2=transforms.Resize(512)
# trans_compose=transforms.Compose([trans_resize_2,trans_totensor])
# img_resize_2=trans_compose(img)
# writer.add_image("resize_2",img_resize_2,4)
#
# # RandomCrop
# trans_random=transforms.RandomCrop((500,1000))
# trans_compose_2=transforms.Compose([trans_random,trans_totensor])
# for i in range(10):
#     img_crop=trans_compose_2(img)
#     writer.add_image("RandomCrop",img_crop,i)
#
#
#
# writer.close()
import torchvision
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

# dataset和transform的联合使用
# import torchvision
# from torch.utils.tensorboard import SummaryWriter
#
# dataset_transfrom=torchvision.transforms.Compose(
#     [
#         torchvision.transforms.ToTensor()
#     ]
# )
#
# train_set=torchvision.datasets.CIFAR10(root="./dataset",train=True,transform=dataset_transfrom,download=True)
# test_set=torchvision.datasets.CIFAR10(root="./dataset",train=False,transform=dataset_transfrom,download=True)

# print(test_set[0])
# print(test_set.classes)
#
# img,target=test_set[0]
# print(img,target)
# print(test_set.classes[target])
# img.show()
#
# print(test_set[0])

# writer=SummaryWriter("p10")
# for i in range(10):
#     img,target=test_set[i]
#     writer.add_image("Test_set",img,i)
#
# writer.close()

# 准备的测试数据集
test_data=torchvision.datasets.CIFAR10("./dataset",train=False,transform=torchvision.transforms.ToTensor())

test_loader=DataLoader(dataset=test_data,batch_size=64,shuffle=True,num_workers=0,drop_last=True)

# 测试数据集中第一张图片及target
img,target=test_data[0]
print(img.shape)
print(target)


wirter=SummaryWriter("dataloader")
step=0
for data in test_loader:
    imgs,targets=data
    # print(imgs.shape)
    # print(targets)
    wirter.add_images("dataloader",imgs,step)
    step+=1
wirter.close()
